home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C08 QuickTime Music / P04 Pick And Play / PickAndPlay.c next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  2.6 KB  |  108 lines  |  [TEXT/KAHL]

  1.  
  2. //____________________________________________________________
  3. //    PickAndPlay.c
  4. //
  5. //    Copyright © Dan Parks Sydow, 1995
  6. //    From the book:
  7. //    "Graphics and Sound Programming Techniques for the Mac",
  8. //    M&T Books, 1995
  9.  
  10.  
  11. //____________________________________________________________
  12.  
  13. #include <QuickTimeComponents.h>
  14.  
  15.  
  16. //____________________________________________________________
  17.  
  18. void  InitializeToolbox( void );
  19. void  InitializeInstrument( long );
  20. void  PlayMusicFromNoteChannel( void );
  21.  
  22.  
  23. //____________________________________________________________
  24.  
  25. #define      kMIDInoInstrument       0
  26.  
  27.  
  28. //____________________________________________________________
  29.  
  30. NoteAllocator    gNoteAllocatorComp;
  31. ToneDescription  gToneDesc;
  32.  
  33.  
  34. //____________________________________________________________
  35.  
  36. void  main( void )
  37. {
  38.    ComponentResult  theResult;
  39.    Str31            thePrompt = "\pSelect an instrument:";
  40.    long             theInstrument = kMIDInoInstrument;
  41.  
  42.    InitializeToolbox();
  43.  
  44.    InitializeInstrument( theInstrument );
  45.  
  46.    theResult = NAPickInstrument( gNoteAllocatorComp, nil, thePrompt, 
  47.                                  &gToneDesc, 0, 0, 0, 0 );
  48.  
  49.    if ( ( gToneDesc.instrumentNumber == 0 ) || ( theResult != noErr ) )
  50.       ExitToShell();
  51.    else
  52.       PlayMusicFromNoteChannel();
  53. }
  54.  
  55.  
  56. //____________________________________________________________
  57.  
  58. void InitializeInstrument( long theInstrument )
  59. {
  60.    ComponentResult  theResult;
  61.  
  62.    gNoteAllocatorComp = OpenDefaultComponent( kNoteAllocatorType, 0 );
  63.  
  64.    theResult = NAStuffToneDescription( gNoteAllocatorComp, theInstrument, &gToneDesc );
  65. }
  66.  
  67.  
  68. //____________________________________________________________
  69.  
  70. void  PlayMusicFromNoteChannel( void )
  71. {
  72.    NoteRequest     theNoteRequest;
  73.    NoteChannel     theNoteChannel;
  74.    short           thePitch;
  75.    ComponentResult theError;
  76.    long            theLong;
  77.  
  78.    theNoteRequest.polyphony = 4;
  79.    theNoteRequest.typicalPolyphony = 0x00010000;
  80.    theNoteRequest.tone = gToneDesc;
  81.  
  82.    theError = NANewNoteChannel( gNoteAllocatorComp, &theNoteRequest, &theNoteChannel );
  83.  
  84.    for ( thePitch = 36; thePitch <= 96; thePitch++ )
  85.    {
  86.       NAPlayNote( gNoteAllocatorComp, theNoteChannel, thePitch, 127 );
  87.       Delay( 10, &theLong );
  88.       NAPlayNote( gNoteAllocatorComp, theNoteChannel, thePitch, 0 );
  89.    }
  90.  
  91.    theError = NADisposeNoteChannel( gNoteAllocatorComp, theNoteChannel );
  92. }
  93.  
  94.  
  95. //____________________________________________________________
  96.  
  97. void  InitializeToolbox( void )
  98. {
  99.    InitGraf( &qd.thePort );
  100.    InitFonts();
  101.    InitWindows();
  102.    InitMenus();
  103.    TEInit();
  104.    InitDialogs( 0L );
  105.    FlushEvents( everyEvent, 0 );
  106.    InitCursor();
  107. }
  108.